<template>
  <div class="song-list" ref="songList">
    <ul>
      <li @click="selectItem(song, index)" class="item" v-for="(song, index) in songs" :key="index">
        <div class="rank">
          <span :class="getRankCls(index)" v-text="getRankText(index)"></span>
        </div>
        <div class="content">
          <h2 class="name">{{song.name}}</h2>
          <p class="desc">{{getDesc(song)}}</p>
        </div>
      </li>
    </ul>
    <div class="loading" v-show="songs.length===0 ? 1:0">
      <Loading></Loading>
    </div>
  </div>
</template>

<script>
import { playlistMixin } from "assets/js/mixin";
import Loading from "base/loading/Loading";
export default {
  mixins: [playlistMixin],
  components: {
    Loading
  },
  props: {
    songs: {
      type: Array
    },
  },
  methods: {
    handlePlaylist(playlist) {
      if (this.$refs.songList) {
        const bottom = playlist.length > 0 ? "60px" : ""

        this.$refs.songList.style.paddingBottom = bottom
        // this.$refs.toplist.refresh();
        this.$emit("scrollRefresh")
      }
    },
    selectItem(item, index) {
      this.$emit("select", item, index)
    },
    getDesc(song) {
      return `${song.singer}·${song.album}`
    },
    getRankCls(index) {
      if (index <= 2) {
        return `icon icon${index}`
      } else {
        return "text"
      }
    },
    getRankText(index) {
      if (index > 2) {
        return index + 1
      }
    }
  }
}
</script>

<style scoped lang="scss">
@import "@/assets/css/mixin.scss";
.song-list {
  width: 100%;
  box-sizing: border-box;
  position: relative;
  background: $background-color;
}
.song-list ul {
  padding: rem(20) rem(30);
}
.item {
  width: 100%;
  height: rem(64);
  box-sizing: border-box;
  overflow: hidden;
}
.rank {
  float: left;
  line-height: rem(64);
}
.text {
  display: inline-block;
  width: rem(25);
  height: 100%;
  margin-right: rem(30);
  color: $font-color;
  font-size: rem(18);
  text-align: center;
}
.icon {
  display: inline-block;
  width: rem(25);
  height: rem(24);
  background-size: rem(25) rem(24);
  margin-right: rem(30);
}
.icon0 {
  background-image: url("./first@3x.png");
}
.icon1 {
  background-image: url("./second@3x.png");
}
.icon2 {
  background-image: url("./third@3x.png");
}
.content {
  color: #fff;
  font-size: rem(15);
  float: left;
  max-width: rem(250);
}
.name {
  max-width: rem(250);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: rem(15);
}
.desc {
  max-width: rem(250);
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: rem(10);
  color: rgba(255, 255, 255, 0.3);
}
</style>
